<?php
/////////////////////////////////////////////////////////////////////////////
// 
//
// workflow_system 
//
// workflow_copyright
// 
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : baseinfo.class.php   FILE_PATH : \\classes\application\baseinfo.class.php
 * ....基本信息管理类
 *
 * @copyright workflow_system 
 * @author workflow Develop Team 
 * @package 
 * @subpackage 
 * @version Wed Sep 19 15:29:03 CST 2007
 */
defined('Base_Use_Sign') or die("this is invalid system!please contact <a href='http://www.shopnc.net'>www.shopnc.net</>.");

class BaseInfoClass extends FrameWork {
	var $obj_config;
	var $charset = "UTF-8";//编码类型
	/**
	 * 修改配置文件信息 
	 * @author workflow Develop Team     
	 * @param  $input_param 修改内容，$genre 修改部分
	 * @return int/bool/object/array
	 */
	function modiBaseInfo($input_param,$genre){
		if (!is_object($this->obj_config)){
			require_once(BasePath."/classes/libraries/inifileoperate.class.php");
			$this->obj_config = new IniFileOperate(BasePath . "/config/config.ini.php");
		}
		//转码
		if(strtoupper($this->charset) == 'GBK'){
			if (is_array($input_param)){
				foreach ($input_param as $k => $v){
					if (is_array($v)){
						$line = serialize($v);
						$line = Common::nc_change_charset($line,'gbk_to_utf8');
						$input_param[$k] = unserialize($line);
					}else {
						$input_param[$k] = Common::nc_change_charset($v,'gbk_to_utf8');
					}
				}
			}
		}
		switch($genre){
			case "setting":
				$this->obj_config->setIniFile("websit","site_name",$input_param["txtsitename"]);
				$this->obj_config->setIniFile("websit","logo_url",$input_param["txtlogourl"]);
				$this->obj_config->setIniFile("websit","poweredby",$input_param["txtpoweredby"]);
				$this->obj_config->setIniFile("websit","icprecord",$input_param["txticprecord"]);
				$this->obj_config->setIniFile("contact","companyname",$input_param["txtcompany"]);
				$this->obj_config->setIniFile("contact","contactman",$input_param["txtcontactman"]);
				$this->obj_config->setIniFile("contact","genre",$input_param["rdogenre"]);
				$this->obj_config->setIniFile("contact","email",$input_param["txtemail"]);
				$this->obj_config->setIniFile("contact","province",$input_param["txtProvince"]);
				$this->obj_config->setIniFile("contact","city",$input_param["txtCity"]);
				$this->obj_config->setIniFile("contact","address",$input_param["txtaddress"]);
				$this->obj_config->setIniFile("contact","fax",$input_param["txtfax"]);
				$this->obj_config->setIniFile("contact","mobilephone",$input_param["txtmobilephone"]);
				$this->obj_config->setIniFile("contact","zip",$input_param["txtzip"]);
				$this->obj_config->setIniFile("contact","contactphone",$input_param["txtphone"]);
				$this->obj_config->setIniFile("websit","site_title",$input_param["txtsitetitle"]);
				$this->obj_config->setIniFile("websit","meta_keyword",$input_param["txtmetakey"]);
				$this->obj_config->setIniFile("websit","meta_desc",$input_param["txtmetades"]);
				break;
			case "mail":
				$this->obj_config->setIniFile("websit","smtpserver",$input_param["txtsmtpserver"]);
				$this->obj_config->setIniFile("websit","smtpemail",$input_param["txtsmtpemail"]);
				$this->obj_config->setIniFile("websit","smtpuser",$input_param["txtsmtpuser"]);
				$this->obj_config->setIniFile("websit","smtppass",$input_param["txtsmtppass"]);
				$this->obj_config->setIniFile("websit","smtpprot",$input_param["txtsmtpport"]);
				break;
			case "system":
				$this->obj_config->setIniFile("websit","templatesname",$input_param["selTemplateName"]);
				$this->obj_config->setIniFile("file","attachmentspath",$input_param["txtattachmentspath"]);
				$this->obj_config->setIniFile("file","allowuploadmaxsize",$input_param["txtmaxsize"]);
//				$this->obj_config->setIniFile("file","allowuploadimagetype",$input_param["txtimagetype"]);
//				$this->obj_config->setIniFile("file","allowuploadfiletype",$input_param["txtfiletype"]);
				$this->obj_config->setIniFile("file","uploadsavetype",$input_param["rdosavetype"]);
				$this->obj_config->setIniFile("productinfo","imageresize_width",$input_param["txtresize_width"]);
				$this->obj_config->setIniFile("productinfo","imageresize_height",$input_param["txtresize_height"]);
				$this->obj_config->setIniFile("productinfo","imageresize_ifcut",$input_param["rdoifcut"]);
				$this->obj_config->setIniFile("cookie","cookiedomain",$input_param["txtdomain"]);
				$this->obj_config->setIniFile("cookie","cookiepath",$input_param["txtcookiepath"]);
				$this->obj_config->setIniFile("cookie","cookie_expire",$input_param["txtcookieexpire"]);
				$this->obj_config->setIniFile("cookie","session_expire",intval($input_param["txtcookieexpire"]/60));
				$this->obj_config->setIniFile("gdimage","wm_image_sign",$input_param["txtimage_sign"]);
				$this->obj_config->setIniFile("gdimage","wm_image_name",$input_param["txtimage_name"]);
				$this->obj_config->setIniFile("gdimage","wm_image_pos",$input_param["txtimage_pos"]);
				$this->obj_config->setIniFile("gdimage","wm_image_transition",$input_param["txtimage_transition"]);
				$this->obj_config->setIniFile("shopinfo","ifcheck",$input_param["rdoifcheck"]);
//				$this->obj_config->setIniFile("paymode","if_predeposit",$input_param["if_predeposit"]);
				$this->obj_config->setIniFile("subdomain","ifsubdomain",$input_param["ifsubdomain"]);
				if ($input_param["ifsubdomain"] == '0'){
					$this->obj_config->setIniFile("subdomain","domainprefix",'');
					$this->obj_config->setIniFile("subdomain","domainroot",'');
				}else {//开启2级域名
					$this->obj_config->setIniFile("subdomain","domainprefix",$input_param["txt_domainprefix"]);
					$this->obj_config->setIniFile("subdomain","domainroot",$input_param["txt_domainroot"]);
					//将cookie作用域修改为2级域名主域名
					$this->obj_config->setIniFile("cookie","cookiedomain",$input_param["txt_domainroot"]);
				}
				$this->obj_config->setIniFile("websit","gzip",$input_param["gzip"]);
				$this->obj_config->setIniFile("websit","index_html",$input_param["index_html"]);
				$this->obj_config->setIniFile("websit","channel_html",$input_param["channel_html"]);
				$this->obj_config->setIniFile("productinfo","ifhtml",$input_param["product_html"]);
				$this->obj_config->setIniFile("paymode","shop_pay_mode",$input_param["shop_pay_mode"]);
				//发布商品条件
				if ($input_param['output_condition'] != ''){
					$array = array();
					foreach ($input_param['output_condition'] as $k => $v){
						$array[] = $k;
					}
					@array_unique($array);
					$input_param['output_condition'] = implode(',',$array);
				}
				$this->obj_config->setIniFile("productinfo","output_condition",$input_param["output_condition"]);
				break;
			case "setmode":
				$this->obj_config->setIniFile("paymode","shop_pay_mode",$input_param['setShopPayType']);
				break;
			case "image":
				//取键值
				$type = @array_keys($input_param);
				if ($type[0] == 'wm_image'){//水印
					$this->obj_config->setIniFile("gdimage","wm_image_name",$input_param['wm_image']);
				}
				break;
		}
	}
	
	/**
	 * 清理缓存
	 * @author workflow Develop Team     
	 * @param  
	 * @return bool
	 */
	function clear_all_cache($file_url){
		$d = dir( $file_url );
		while ( FALSE !== ( $entry = $d->read() ) )
		{
			if ( $entry == '.' || $entry == '..' ){
				continue;
			}
			$entry = $file_url . '/' . $entry;
			if ( is_dir( $entry ) )	{
				$this->clear_all_cache( $entry );
			}else if (is_file($entry)){
				@unlink( $entry );
			}
		}
		$d->close();
		return true;
	}
	
	/**
	 * 清理模板缓存
	 * @author workflow Develop Team     
	 * @param  
	 * @return int/bool/object/array/string
	 */
	function clear_templates_cache($file_url){
		$d = dir( $file_url );
		while ( FALSE !== ( $entry = $d->read() ) )
		{
			if ( $entry == '.' || $entry == '..' ){
				continue;
			}
			if ($entry == 'templates_c'){
				$entry = $file_url . '/' . $entry;
				if (is_dir( $entry )){
					$this->clear_all_cache( $entry );
				}
			}
		}
		$d->close();
		return true;
	}
	
	/**
	 * 修改支付方式配置文件信息 
	 * @author workflow Develop Team     
	 * @param  $input_param 修改内容，$genre 修改部分
	 * @return bool
	 */
	function modiPaymentInfo($input_param,$genre){
		if (!is_object($this->obj_config)){
			require_once(BasePath."/classes/libraries/inifileoperate.class.php");
			$this->obj_config = new IniFileOperate(BasePath . "/config/payment.ini.php");
		}
		//转码
		if(strtoupper($this->charset) == 'GBK'){
			if (is_array($input_param)){
				foreach ($input_param as $k => $v){
//					if(function_exists('iconv') && ICONV_VERSION < 2){
//						$input_param[$k]=iconv('GBK//IGNORE','UTF-8',$v);
//					}else{
//						$input_param[$k] = mb_convert_encoding($v, "UTF-8", "GBK");
						$input_param[$k] = Common::nc_change_charset($v,'gbk_to_utf8');
//					}
				}
			}
		}
		switch($genre){
			case "online":
				$this->obj_config->setIniFile("online","alipay",$input_param["txtalipay"]);
				$this->obj_config->setIniFile("online","alipay_partner",$input_param["txtalipay_partner"]);
				$this->obj_config->setIniFile("online","alipay_security_code",$input_param["txtalipay_security_code"]);
				$this->obj_config->setIniFile("online","tenpay",$input_param["txttenpay"]);
				$this->obj_config->setIniFile("online","tenpay_key",$input_param["txttenpay_key"]);
				break;
		}
	}
	
}
?>